﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using ProgNetComponents.Utils.EventHandlers;

namespace ProgNetComponents.Validation.Rules
{
    /// <summary>
    /// Custom validation rule. Allows to validate row with custom function passed to RowValidated event
    /// </summary>
    public class CustomValidationRule : ValidationRule
    {
        /// <summary>
        /// Occurs when [row validated].
        /// </summary>
        public event DataRowValidationHandler RowValidated;

        /// <summary>
        /// Initializes a new instance of the <see cref="CustomValidationRule"/> class.
        /// </summary>
        public CustomValidationRule()
        {
            
        }

        /// <summary>
        /// Does the validate.
        /// </summary>
        /// <param name="row">The row.</param>
        /// <returns></returns>
        protected override bool DoValidate(DataRow row)
        {
            DataRowValidationEventArgs e = new DataRowValidationEventArgs(row);
            if (RowValidated != null)
            {
                RowValidated(this, e);
            }
            return e.ValidationPassed;
        }
    }
    
   
}
